package drawer

import (
	"MetroBuilderGameJam/gameEngine/geom"
	"github.com/hajimehoshi/ebiten/v2"
	"github.com/hajimehoshi/ebiten/v2/vector"
	"image/color"
)

func Line(dst *ebiten.Image, from, to geom.Point, w float64, clr color.Color) {
	vector.StrokeLine(dst, float32(from.X), float32(from.Y), float32(to.X), float32(to.Y), float32(w), clr, false)
}

func (d *Drawer) BendedLine(dst *ebiten.Image, from, to geom.Point, w float64, clr color.Color) (autoCollider geom.Collider) {
	bendPoint := geom.CalcBendPosition(from, to)
	if bendPoint == from || bendPoint == to {
		Line(dst, from, to, w, clr)
	}

	path := vector.Path{}
	path.MoveTo(float32(from.X), float32(from.Y))
	path.LineTo(float32(bendPoint.X), float32(bendPoint.Y))
	path.LineTo(float32(to.X), float32(to.Y))

	vs, is, op := d.preparePathToDraw(path, w, clr)
	d.drawPath(dst, vs, is, op)

	autoCollider = geom.MakeTrianglesCollider(vs, is)

	return autoCollider
}
